package com.brs.model;

import java.util.Date;
import java.util.concurrent.TimeUnit;

public class Issue {
	private Borrower borrower;
	private Manager manager;
	private BookItem bookItem;
	private Date issuedDate;
	private Date returnedDate;
	private float bill;

	public Borrower getBorrower() {
		return borrower;
	}

	public void setBorrower(Borrower borrower) {
		this.borrower = borrower;
	}

	public Manager getManager() {
		return manager;
	}

	public void setManager(Manager manager) {
		this.manager = manager;
	}

	public BookItem getBookItem() {
		return bookItem;
	}

	public void setBookItem(BookItem bookItem) {
		this.bookItem = bookItem;
	}

	public Date getIssuedDate() {
		return issuedDate;
	}

	public void setIssuedDate(Date issuedDate) {
		this.issuedDate = issuedDate;
	}

	public Date getReturnedDate() {
		return returnedDate;
	}

	public void setReturnedDate(Date returnedDate) {
		this.returnedDate = returnedDate;
	}

	public float getBill() {
		return bill;
	}

	public float calBill() {
		if (returnedDate != null && returnedDate.after(issuedDate)) {
			long days = TimeUnit.DAYS.convert(returnedDate.getTime() - issuedDate.getTime(), TimeUnit.MILLISECONDS);
			bill = borrower.getDailyFee() * days;
		} else {
			// TODO: Deal with exceptions
		}

		return bill;
	}

	@Override
	public String toString() {
		return "Issue [borrower=" + borrower + ", bookItem=" + bookItem + ", issuedDate=" + issuedDate
				+ ", returnedDate=" + returnedDate + ", bill=" + bill + "]";
	}

}
